<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="commontaglib"%>
<%
String path = request.getContextPath();

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
 
<html>
  <head>
    <link rel="stylesheet" href="<%=path%>/css/innerstyle.css" type="text/css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<%=path%>/css/cupertino/jquery-ui.custom.min.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<%=path%>/css/ui.jqgrid.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<%=path%>/css/ui.multiselect.css" />
    <script type="text/javascript" src="<%=path%>/js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="<%=path%>/js/jquery-ui.custom.min.js"></script>  
    <script type="text/javascript" src="<%=path%>/js/i18n/grid.locale-cn.js"></script> 
    <script type="text/javascript" src="<%=path%>/js/jquery.jqGrid.min.js"></script>
    <script type="text/javascript" src="<%=path%>/js/i18n/jquery.ui.datepicker-zh-CN.js"></script>
    <style>
html, body {
	margin: 0;			 
	padding: 0;
	 
    font-size: 85%;
}
</style>
    
  </head>
  
  <script type="text/javascript">  
  var qieye = 0;
    $(function(){ 
	queryNum();
    $("#xinz").button(); 
    $("#chax").button();
    $("#shanc").button();
    $("#tib").button();
    $("#daoc").button();
	 $("#daoc").hide();
    $("#fuz").button(); 
    $("#reset").button();
    loadTab(0);
    $( "#datepicker" ).datepicker($.datepicker.regional[ "zh-CN" ]);
    $( "#datepicker1" ).datepicker($.datepicker.regional[ "zh-CN" ]);
    $( "#tabs" ).tabs({
		    select: function(event, ui) {
		    var i =ui.index;	    
		    if(i==''){
		    i="0";
		    }
		    qieye = i;
		    loadTab(i);
		    $("#myTab"+qieye).jqGrid('setGridParam',{url:'bdcxJqgrid.action?index='+qieye,mtype:'post',page:1}).trigger("reloadGrid");
		   // alert("aa");
		    if(i==1){
		     $("#myTab"+qieye).jqGrid('hideCol',["ydl"]);
			 $("#myTab"+qieye).jqGrid('hideCol',["cjl"]);
		    }
			if(i==2){
		    $("#myTab"+qieye).jqGrid('hideCol',["cjl"]);
		    }
			
			queryNum();
            //return false;           
  		  }
		
	});
 });
 function queryNum(){   
		
			  var formdata = $("#form1").serialize(); 
			  $.post("<%=path%>/gpjy/findBdcxList4Num.action?",formdata+'&index='+qieye,function(data,textStatus)
			  {
			  
			  var json = eval('(' + data + ')');
			
			  var re=/(\d{1,3})(?=(\d{3})+(?:$|\.))/g;
	if (json[0].zongsl !="")
{
			   $("#queryNum").html("价格范围："+json[0].zongjg + "元/吨  总数量："+json[0].zongsl.toString().replace(re,"$1,")+"吨  总金额："+json[0].zongje.toString().replace(re,"$1,")+"元");
			}else
			{
			 $("#queryNum").html("价格范围：0 元/吨  总数量：0 吨  总金额：0 元");
			}  });
			
  
               }
 function loadTab(i){ 
    var sign = true;
   
    $("#myTab"+i).jqGrid({      
    url:'bdcxJqgrid.action?index='+i,  
    datatype: 'json',
    mtype: 'post',         
   	colNames:['操作','报单号','发货单位名称','煤种','品种','价格类型','价格','报单数量','应单数量','成交数量','合同形式','隶属行业','报单日期','报单状态',],
   	colModel:[ 
   	    {name:'Verify',index:'id',width:40,align:"center",sortable:false},
   	    {name:'baodbh',index:'baodbh', width:120},
   		{name:'sfahdwname',index:'sfahdwname', width:260},
   		{name:'meizname',index:'meizname', width:80 },	
   		{name:'pinzname',index:'pinzname', width:80 },
   	    {name:'jiaglxname',index:'jiaglxname', width:80 },
   		{name:'danj',index:'danj', width:60 },
   		{name:'shul',index:'shul', width:60 },
		{name:'ydl',index:'ydl', width:60 },
		{name:'cjl',index:'cjl', width:60 },
   		{name:'hetxsname',index:'hetxsname', width:60 },
   		{name:'lisname',index:'lisname', width:60 },
   		{name:'baodsj',index:'baodsj', width:80},	
   		{name:'danjztname',index:'danjztname', width:80, sortable:false}		
   	],
   
    jsonReader: {
           repeatitems : false, 
           id: 'baodbh'
         },    	
	width: 1065, 
   shrinkToFit:false,
   	rowNum:10,
   	rowList:[10,20,30],     	
   	pager: '#pager'+i,   	
   	rownumbers: true,   	 
    viewrecords: true,
    multiselect: sign,
    sortorder: 'desc',  
    altRows:true,  
	//caption: "报单列表",
	loadComplete:function()
	{ //在此事件中循环为每一行添加修改和删除链接 
	
	
		var ids=jQuery("#myTab"+i).jqGrid('getDataIDs'); 
		for(var j=0; j<ids.length; j++)
		{ 
			var id=ids[j];
			
			//if(i==1){
			verify ="<a href='#' style='color:#f60' onclick='select("+ id +")'>查看</a>";
			//}else{
			//verify ="<a href='#' style='color:#f60' onclick='select("+ id +")'>查看</a>";
			//}			
			jQuery("#myTab"+i).jqGrid('setRowData',ids[j], { Verify: verify }); 
		} 
	} 	
  });
  $("#myTab"+i).jqGrid('setGridHeight','250px');
  //$("#myTab"+i).jqGrid('hideCol',["chumdwmc"]);
  
	
  }

// 查询
function search(){ 
  //alert("aaa");  
  var formdata = $("#form1").serialize();  
  $("#myTab"+qieye).jqGrid('setGridParam',{url:'bdcxJqgrid.action?'+formdata+'&index='+qieye,mtype:'post',page:1}).trigger("reloadGrid"); 
}

function openwindow(url){
    var sheight = screen.height-70;
    var swidth = screen.width-10;
   var winoption ="dialogHeight:"+sheight+"px;dialogWidth:"+ swidth +"px;status:yes;scroll:yes;resizable:yes;center:yes";
    var result=window.showModalDialog(url,window,winoption);
    //alert(result);
    if(result ==1){
     reloadbdxx();
      }
    return result;  
}

function reloadbdxx(){
   window.location.href="<%=request.getContextPath()%>/gpjy/bdcxList.action";
}

function removeRow() {
    var s = $("#myTab0").jqGrid('getGridParam','selarrrow');
	if (s == "") {
        alert("请先选择报单，再点击删除！");
        return;
    }
	var url = "<%=path%>/gpjy/removeBdxxInfo.action?bdbh="+s;
	$( "#dialog-confirm" ).dialog({
			resizable: false,
			height:140,
			modal: true,
			buttons: {
				"确认": function() {
					$.post(url, function(data) {
                    var json =eval('(' + data + ')');
					if(json.result==1){
					   alert("删除成功！");
					   reloadbdxx();
					}else{
					   alert("删除失败！");
					}                                    
                   }); 
                   $( this ).dialog( "close" );                   
				},
				"返回": function() {
					$( this ).dialog( "close" );
				}
			}
		});
}

function submitRow() {
	var s = $("#myTab0").jqGrid('getGridParam','selarrrow');
	if (s == "") {
        alert("请先选择报单，再点击提交！");
        return;
    }
	var url = "<%=path%>/gpjy/submitBdxxInfo.action?bdbh="+s;
	$( "#dialog-confirm1" ).dialog({
			resizable: false,
			height:140,
			modal: true,
			buttons: {
				"确认": function() {
					$.post(url, function(data) {
					var json =eval('(' + data + ')');
                    if(json.result==1){					   
					   alert("提交成功！");
					   reloadbdxx();
					   }else{					  
					   alert("提交失败！"+json.msg);
					   }   
                   });                  
                   $( this ).dialog( "close" );                    
				},
				"返回": function() {
					$( this ).dialog( "close" );
				}
			}
		});

}

function copyRow(){
    var s = $("#myTab0").jqGrid('getGridParam','selarrrow');
    if (s == "") {
        alert("请先选择报单，再点击复制！");
        return;
    }
	var url = "<%=path%>/gpjy/copyBdxxInfo.action?bdbh="+s;
	$( "#dialog-confirm2" ).dialog({
			resizable: false,
			height:140,
			modal: true,
			buttons: {
				"确认": function() {
					$.post(url, function(data) {
                       var json =eval('(' + data + ')');
					   if(json.result==1){
					   alert("复制成功！");
					   reloadbdxx();
					   }else{
					   alert("复制失败！");
					   }
                   });                   
                   $( this ).dialog( "close" );                   
				},
				"返回": function() {
					$( this ).dialog( "close" );
				}
			}
		});
}

function select(id) { //单击修改链接的操作
 if (id.id!=undefined){
 openwindow('<%=path %>/gpjy/findYdxxInfo4cx.action?&bdbh='+id.id );
 }else{
    var bdbh = id.item(1).cells.item(3).innerHTML;
    openwindow('<%=path %>/gpjy/findYdxxInfo4cx.action?&bdbh='+bdbh );
 }
}

//重置
function resetSearch(){
	$('#list_search  input[type=text]').val('');
	$('#list_search select').val('-1');
}

function dc_excel(){ 
	form1.action="<%=path%>/htgl/jytj_excel.action?index=0";
	form1.method = "post";
	form1.submit();
	}

</script>  
<body>  
<div id="best1">
<p></p>
<form id="form1" method="post">

<table id="list_search" cellpadding="0" cellspacing="0" border="0"> 
        <tr>
        	<td>报单号:</td>
            <td><input type="text" class="longtextbox" name="bean.AA" /></td>
            <td>
                煤种:
            </td>
            <td>
            	<div class="select"><div><s:select name="bean.BB" headerKey="-1" headerValue="请选择"  list="mzList" listKey="diccode" listValue="dicname" id="combobox"/></div></div> 
            </td>            
            <td>
               品种 :
            </td>
            <td>
            	<div class="select"><div><s:select name="bean.CC" headerKey="-1" headerValue="请选择"  list="pzList" listKey="diccode" listValue="dicname" /></div></div>
            </td>
        </tr>  
		
		<tr>
        <td>买受人:</td>
        <td><input type="text" class="longtextbox" name="bean.DD" /></td>
        <td>收货单位:</td>
        <td><input type="text" class="longtextbox" name="bean.EE" /></td>
        <td>出省站/营业站:</td>
        <td><input type="text" class="longtextbox" name="bean.FF" /></td>
        </tr>      
        <tr>
        <td>合同形式:</td>
        <td><div class="select"><div><s:select name="bean.GG" headerKey="-1" headerValue="请选择"  list="htxsList" listKey="diccode" listValue="dicname" /></div></div></td>
        <td>隶属行业:</td>
        <td><div class="select"><div><s:select name="bean.HH" headerKey="-1" headerValue="请选择"  list="hyList" listKey="diccode" listValue="dicname" /></div></div></td>
        <td>到达省/市地:</td>
        <td><input type="text" class="longtextbox" name="bean.II" /></td>
        </tr>
        <tr>
        <td>价格:</td>
        <td><input type="text" class="textboxs" name="bean.JJ" onKeyUp="this.value=this.value.replace(/\D/g,'');" />
          --
          <input type="text" class="textboxs" name="bean.KK" onKeyUp="this.value=this.value.replace(/\D/g,'');" /></td>
        <td>数量:</td>
        <td><input type="text" class="textboxs" name="bean.LL" onKeyUp="this.value=this.value.replace(/\D/g,'');" />
          --
          <input type="text" class="textboxs" name="bean.MM" onKeyUp="this.value=this.value.replace(/\D/g,'');" /></td>
        <td>报单日期:</td>
            <td>
            	<input id="datepicker" type="text" class="textboxs" name="bean.NN" /> 
            	-- 
            	<input id="datepicker1" type="text" class="textboxs" name="bean.OO" />
            </td>
        </tr>
        
		<tr>			
            <td colspan="5" style="float:right">
            <input id="chax" type="button" value="查询" onclick="search();queryNum();"/>
            <input id="reset" type="button" value="重置" onclick="resetSearch();"/>
            </td>
            <td>&nbsp;</td>
        </tr>
  </table> 
  </form>   
    <table id="list_search" cellpadding="0" cellspacing="0" border="0">
    <tr>
		    <td align="left">
		    <input id="daoc" type="button" value="导出Excel"  onclick="dc_excel();"/>&nbsp;&nbsp;&nbsp;&nbsp;      </td>
            
            
      </tr>
    </table>
    <div id="tabs">
			<ul>
				<li><a href="#tabs-0">全部</a></li>
				<li><a href="#tabs-1">待应单</a></li>
				<li><a href="#tabs-2">待成交</a></li>
				<li><a href="#tabs-3">已成交</a></li>	
				<li id="queryNum"  style="float:right; vertical-align: bottom; line-height:20px; top: 3px;"></li>			
			</ul>
			<div id="tabs-0">
				<table id="myTab0" class="scroll" cellpadding="0" cellspacing="0"></table>
				<div id="pager0" class="scroll"></div>
				<div id="message0" class="scroll"></div>
			</div>
			<div id="tabs-1">
				<table id="myTab1" class="scroll" cellpadding="0" cellspacing="0"></table>
				<div id="pager1" class="scroll"></div>
				<div id="message1" class="scroll"></div>
			</div>
			<div id="tabs-2">
				<table id="myTab2" class="scroll" cellpadding="0" cellspacing="0"></table>
				<div id="pager2" class="scroll"></div>
				<div id="message2" class="scroll"></div>
			</div>
			<div id="tabs-3">
				<table id="myTab3" class="scroll" cellpadding="0" cellspacing="0"></table>
				<div id="pager3" class="scroll"></div>
				<div id="message3" class="scroll"></div>
			</div>

   </div>
   <div id="dialog-confirm" title="是否确认删除？"></div>
   <div id="dialog-confirm1" title="是否确认提报？"></div>
   <div id="dialog-confirm2" title="是否确认复制？"></div>
</div> 
</body>
</html>
